<!--
 *  Description: Shows upcoming events
 -->

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<jsp:useBean id="event" scope="session" class="com.asaga.tools.Event_DBImpl" />
<jsp:useBean id="userProfile" scope="session" class="com.asaga.tools.SystemClient_DBImpl" />
<jsp:useBean id="emailBean" scope="session" class="com.asaga.tools.Email_DBImpl" />
<jsp:useBean id="fontBean" scope="session" class="com.asaga.tools.FontBean" />
<jsp:setProperty name="fontBean" property="*" />
<jsp:setProperty name="emailBean" property="*" />

<%@page import="java.sql.*, java.io.*, java.util.*, java.net.*"%>

<html>
    <%@ include file="header.jsp" %>
            <script language="JavaScript">            
            <!-- Sellect all checkbox -->    
            <!--
            function ToggleCheckAll(button) {
                var sa = true;
                
                if(button.checked){ sa = false; }
                
                for (var i=0; i<document.Send.elements.length; i++) {
                
                    if(document.Send.elements[i].type == "checkbox"){
                    var e = document.Send.elements[i];

                    if(sa){
                    e.checked = false;
                    }
                    else{
                    e.checked = true;
                    }
                    } 
                } // end of for
                if(sa){
                button.checked=false;
                }
                else{
                button.checked=true;
                }
            } // end of function
            //-->
            </script>

    <% // Get information of upcoming events
       ResultSet upcomingEventList = emailBean.getUpComingEventList();
    %>
    
<body>
    <div id="container">
            <%@ include file="topNav.jsp" %>
            <%@ include file="leftside.jsp" %>
            <%@ include file="rightside.jsp" %>
            <div id="content">
<table border="0" width="561">
    <tr>
        <td width="555">
            <font size="3"><b>Upcoming Event List</b></font>
        </td>
    </tr>
</table>

    <form name="SendReminders" action="AutismSiteMasterController" method="get">
    <%                  
        // if data exists, then runs
        if (upcomingEventList != null) {             
        out.print("<h4>Please Select Events You Want To Send Email Reminders</h4>");
        out.print("<table border=1 padding=2>");
        out.print("<tr>");
        out.print("<td colspan=\"3\"><font face=\"Arial\">Select All Events:</font></td><td><input type=\"checkbox\" name=\"CheckAll\" onClick=\"ToggleCheckAll(this)\"></td>");
        out.println("</tr>");
        out.print("<tr>");
        out.print("<td>&nbsp</a></td><td><p align=\"center\"><b>Start Date</b></p></td><td><p align=\"center\"><b>Event</b></p></td><td><p align=\"center\"><b>End Date</b></p></td>");
        out.println("</tr>");

        while (upcomingEventList.next()) {
             // Get upcoming event IDs, titles, start dates, and end dates
             String eventID = upcomingEventList.getString("eventID");
             String eventTitle = upcomingEventList.getString("title");
             String eventStartDate = upcomingEventList.getString("startDate");
             String eventEndDate = upcomingEventList.getString("endDate");                         

             out.print("<tr>");
             out.print("<td><input id=\"evtID\" name=\"evtID\" type=\"checkbox\" value=\""+eventID+"\"></td><td>"+eventStartDate+"</td><td>"+eventTitle+"</td><td>"+eventEndDate+"</td>");
             out.println("</tr>");
             } // end of while

        out.print("</table><br>");                    
        out.print("<input id=\"btn1\" type=\"submit\" name=\"action\" value=\"Send Reminders\"></form><br>");
        
        } // end of if

        else {                
        //If there is no upcoming event, then display "Go to the Main"                
        out.println("<h3>There is no upcoming event.</h3>");
        %>

        <form action="index.jsp" method="get">                
        <input type="submit" value="Go to the Main">
        </form>                 
        <% } %>          
                
            </div>
            <%@ include file="footer.jsp" %>
        </div>    
</body>
</html>